package com.wlw.eye.utils

import android.arch.lifecycle.ViewModelProvider
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo

object NetworkUtils {
    fun isNetConneted(context: Context): Boolean {
        val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo: NetworkInfo? = connectivityManager.activeNetworkInfo
        return if (networkInfo == null) false else networkInfo.isConnected && networkInfo.isAvailable
    }

    fun isNetWorkConnected(context: Context, typeMoble: Int): Boolean {
        if (!isNetConneted(context)) return false
        val connectManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val netWorkInfo: NetworkInfo = connectManager.getNetworkInfo(typeMoble)

        return if (netWorkInfo == null) false else netWorkInfo.isConnected && netWorkInfo.isAvailable
    }

    fun isPhoneNetConnected(context: Context): Boolean {
        val typeMobile = ConnectivityManager.TYPE_MOBILE
        return isNetWorkConnected(context, typeMobile)
    }

    fun isWiFiNetConnected(context: Context): Boolean {
        return isNetWorkConnected(context, ConnectivityManager.TYPE_WIFI)
    }
}